package com.ev.apis.controller.custom;


import com.ev.custom.domain.DieArchivesDO;
import com.ev.custom.service.DieArchivesPageParam;
import com.ev.custom.service.DieArchivesService;
import com.ev.custom.vo.DieArchivesParam;
import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(value = "二次开发-基础信息-模具档案 前端控制器", tags = "二次开发-基础信息-模具档案 前端控制器")
@RestController
@RequestMapping("/apis/dieArchives")
public class DieArchivesController{
	@Autowired
	private DieArchivesService dieArchivesService;

	@EvApiByToken(value = "/list", method = RequestMethod.POST, apiTitle = "分页信息展示")
	@ApiOperation("分页信息展示")
	@Transactional(rollbackFor = Exception.class)
	public R listForTenant(@Valid @RequestBody @ApiParam("参数") DieArchivesPageParam param) {
		return R.ok().put("data",dieArchivesService.list(param));
	}

	@EvApiByToken(value = "/detail", method = RequestMethod.GET, apiTitle = "详细")
	@ApiOperation("详细")
	@Transactional(rollbackFor = Exception.class)
	public R detail(@ApiParam(value = "ID", required = true) @RequestParam(value = "id", defaultValue = "", required = false) Long id) {
		return R.ok().put("data",dieArchivesService.detail(id));
	}

	@EvApiByToken(value = "/saveOrUpdate", method = RequestMethod.POST, apiTitle = "暂存/修改")
	@ApiOperation("保存/修改")
	@Transactional(rollbackFor = Exception.class)
	public R saveAndUpdateForManagement(@Valid @RequestBody @ApiParam("参数") DieArchivesDO param) {
		try {
			dieArchivesService.saveUpdate(param);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error(e.getLocalizedMessage());
		}
	}

	@EvApiByToken(value = "/audit", method = RequestMethod.POST, apiTitle = "审核/反审核")
	@ApiOperation("审核/取消审核")
	@Transactional(rollbackFor = Exception.class)
	public R saveAndCommit(@Valid @RequestBody @ApiParam("参数") DieArchivesParam param) {

		try {
			dieArchivesService.audit(param);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error(e.getLocalizedMessage());
		}
	}

	@EvApiByToken(value = "/del", method = RequestMethod.POST, apiTitle = "删除/批量删除")
	@ApiOperation("删除/批量删除")
	@Transactional(rollbackFor = Exception.class)
	public R remove(@Valid @RequestBody @ApiParam("参数") Long[] ids) {
		try {
			dieArchivesService.del(ids);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error(e.getLocalizedMessage());
		}
	}
}
